<?php

class ContactusController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function indexAction() {
        $form = new Application_Form_Contactus();
        $this->view->form = $form;

        if ($this->getRequest()->isPost()) {
            if ($form->isValid($this->getRequest()->getPost())) {
                $values = $form->getValues();
                $this->sendMail($values);
                $this->view->isSent = true;
            }
        }
    }

    public function sendMail($data) {
        $optionDb = new Admin_Model_Options();
        $fromEmail = $data['email'];
        $fromName = $data['name'];
        $toEmail = $optionDb->getAdminEmail();
        $toName = 'admin';
        $subject = $data['subject'];
        $body = $data['message'];
        $mail = new Zend_Mail();
        $mail->setFrom($fromEmail, $fromName);
        $mail->addTo($toEmail, $toName);
        $mail->setSubject($subject);
        $mail->setBodyHtml($body);
        $mail->send();
    }

}

